﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Register : System.Web.UI.Page
{
    AccessData ac = new AccessData();
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (CheckRegis())
        {
            string username = txtUsername.Text;
            string pass = txtPassword.Text;
            string cusname = txtCustomerName.Text;
            string sql = "Insert into Customers values('" + username + "','" + pass + "','" + cusname + "')";
            ac.ExeCuteQuery(sql);
            Response.Redirect("Default.aspx");
        }
    }
    public bool CheckRegis()
    {
        string sql = "select UserName from Customers";
        SqlDataReader dr =  ac.ExecuteReader(sql);
        while (dr.Read())
        {
            if (dr[0].ToString() == txtUsername.Text)
            {
                lblStatus.Text = "Username invalid";
                return false;
            }
        }
        if (txtUsername.Text =="" || txtUsername.Text == null)
        {
            lblStatus.Text = "Username invalid!!!";
            txtUsername.Focus();
            return false;
        }
        if (txtPassword.Text == "" || txtPassword.Text ==null)
        {
            lblStatus.Text = "Password invalid!!!";
            txtPassword.Focus();
            return false;
        }
        if (txtRePassword.Text == "" || txtRePassword.Text == null)
        {
            lblStatus.Text = "Re-Password invalid!!!";
            txtRePassword.Focus();
            return false;
        }
        if (txtRePassword.Text != txtPassword.Text)
        {
            lblStatus.Text = "Re-Password invalid!!!";
            txtRePassword.Focus();
            return false;
        }
        if (txtCustomerName.Text == "" || txtCustomerName.Text == null)
        {
            lblStatus.Text = "Real Name invalid!!!";
            txtCustomerName.Focus();
            return false;
        }
        return true;
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
}
